<?php
/**
 * 
 *
 * PHP version 5.3.x
 *
 * @category 
 * @package  
 * @author   gouki <gouki.xiao@gmail.com>
 */

/**
 * SaeFileCache.php
 *
 * @category 
 * @package  
 * @author   gouki <gouki.xiao@gmail.com>
 * @version $Id$ 
 * @created 2011-11-23 09:47
 */ 
class SaeFileCache extends CFileCache{
	private $_gcProbability=100;
	private $_gced=false;
	/**
	 * Stores a value identified by a key in cache.
	 * This is the implementation of the method declared in the parent class.
	 *
	 * @param string $key the key identifying the value to be cached
	 * @param string $value the value to be cached
	 * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
	 * @return boolean true if the value is successfully stored into cache, false otherwise
	 */
	protected function setValue($key,$value,$expire)
	{
		if(!$this->_gced && mt_rand(0,1000000)<$this->_gcProbability)
		{
			$this->gc();
			$this->_gced=true;
		}

		if($expire<=0)
			$expire=31536000; // 1 year
		$expire+=time();

		$cacheFile=$this->getCacheFile($key);
        $saeStorage = new SaeStorage();
        $saeStorage->write(SaeCommon::getSaeStorage('runtime'),$cacheFile,$value,-1,array("expire"=>$expire));
//		if($this->directoryLevel>0)
//			@mkdir(dirname($cacheFile),0777,true);
//		if(@file_put_contents($cacheFile,$value,LOCK_EX)!==false)
//		{
//			@chmod($cacheFile,0777);
//			return @touch($cacheFile,$expire);
//		}
//		else
//			return false;
	}
}
